package com.ljx.rpc.core.domain.dto;

import com.ljx.rpc.core.domain.enums.RpcCodeEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @Author: LiJunXi
 * @Description:
 * @Date: 2024-10-05  15:25
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class RpcResponse<T> implements Serializable {

    private T data;

    private Integer code;

    private String requestId;

    public static <T> RpcResponse<T> success(T obj, String requestId){
        return new RpcResponse(obj, RpcCodeEnum.SUCCESS.getKey(), requestId);
    }

    public static <T> RpcResponse<T> fail(T obj, String requestId){
        return new RpcResponse(obj, RpcCodeEnum.FAIL.getKey(), requestId);
    }
}
